package com.wn55.hrms.web.controller;

import com.github.pagehelper.PageInfo;
import com.wn55.hrms.entity.Evection;
import com.wn55.hrms.entity.OverTime;
import com.wn55.hrms.service.EvectionService;
import com.wn55.hrms.util.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Mr.bai~
 * @version 1.0
 * @date 2022/5/6 17:09
 */
@RestController
@RequestMapping("evection")
@Api(value = "本接口是用来操作出差表功能")
public class EvectionController {

    @Autowired
    EvectionService evectionService;



    @GetMapping("/evectionList")
    @ApiOperation(value = "分页查询渠道列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",dataType = "int",name="now",value = "查询当前页",required = false,defaultValue = "1"),
            @ApiImplicitParam(paramType = "query",dataType = "int",name="size",value ="查询每页条数",required = false,defaultValue = "2"),
            @ApiImplicitParam(paramType = "query",dataType = "string",name="eName",value = "员工名称",required = false),
            @ApiImplicitParam(paramType = "query",dataType = "string",name="type",value = "加班类型",required = false),
    })
    public ResultResponse<PageInfo<Evection>> evectionList(
            @RequestParam(value = "now", defaultValue = "1") Integer now,
            @RequestParam(value = "size", defaultValue = "2") Integer size,
            String eName, String type){
        ResultResponse<PageInfo<Evection>> result = null;
        try {

            PageInfo<Evection> pageInfo = evectionService.queryEvection(now, size, eName, type);
            result = new ResultResponse<>(200, "查询成功", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            result = new ResultResponse<>(404, "查询失败");
        }
        return result;
    }

    @DeleteMapping("/del/{id}")
    @ApiOperation(value = "根据标识ID删除渠道")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path",dataType = "int",name = "id",value = "加班记录的ID标识")
    })
    public ResultResponse<Void> delete(@PathVariable("id") int id) {

        ResultResponse<Void> result = null;

        try {
            evectionService.removeBykey(id);
            result = new ResultResponse<>(200, "删除出差成功!");
        } catch (Exception e) {
            e.printStackTrace();
            result = new ResultResponse<>(201, "删除出差失败!");
        }
        return result;
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加出差信息")
    public ResultResponse<Void> addEvection(@RequestBody Evection evection) {
        System.out.println(evection.geteId());
        ResultResponse<Void> result = null;
        try {
            evectionService.addEvection(evection);
            result = new ResultResponse<>(200, "添加出差成功!");
        } catch (Exception e) {
            e.printStackTrace();
            result = new ResultResponse<>(201, "添加出差失败!");
        }
        return result;
    }
    @PutMapping("/modify")
    @ApiOperation(value = "修改出差记录")
    public ResultResponse<Void> modifyOverTime(@RequestBody Evection evection) {

        ResultResponse<Void> result = null;
        try {
            evectionService.modifyEvection(evection);
            result = new ResultResponse<>(200, "修改出差成功!");
        } catch (Exception e) {
            e.printStackTrace();
            result = new ResultResponse<>(201, "修改出差失败!");
        }
        return result;
    }




}
